package com.franklin.springbootdemo.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.franklin.springbootdemo.DemoService;
import com.franklin.springbootdemo.ISimpleService;
import com.franklin.springbootdemo.ResponseVo;
import com.franklin.springbootdemo.SimpleMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.*;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

@RequestMapping("/demo")
@RestController
@RequiredArgsConstructor
public class DemoController {

    private final DemoService demoService;
    private final SimpleMapper simpleMapper;
    private final ISimpleService simpleService;

    /**
     * @param str
     */
    @GetMapping("/do1")
    public String do1(String str) {
//        StrUtil.isBlankIfStr()
        System.out.println(str);
        if (str.equals("true")) {
            throw new RuntimeException();
        }
        return str;
    }

    @PostMapping("/do2")
    public DemoEntity do2(@RequestBody DemoEntity demoEntity, DemoEnum demoEnum) {
        return demoEntity;
    }

    public static String test() {
        return "";
    }

    @PostMapping("/file")
    public void upload(MultipartFile multipartFile) {
        System.out.println(multipartFile.getName());
    }

    @PostMapping("/date")
    public void date(Date date) {
        System.out.println(date);
    }

    public void getDemoEntityList(Integer num) {
        demoService.getDemoEntityList(num)
                .forEach(System.out::println);
    }

    public void test(
            HttpServletRequest httpServletRequest,
//            int i,
//            boolean b,
//            Date date,
//            String a,
//            DemoEnum demoEnum,
            Map<String, ? extends DemoEntity> demoEntityMap,
//            Map<? extends DemoEntity,? extends DemoEntity> demoEntityMap1,
//            Collection<DemoEntity> demoEntityCollection,
            List<DemoEntity> demoEntityList,
            DemoEntity[] demoEntityArr
            ,
            DemoEntity... demoEntityVars
    ) {
        Arrays.asList(demoEntityArr).forEach(System.out::println);
    }

    @PostMapping("/files")
    public void file(
            Map<Object, Object> map,
            MultipartFile multipartFile
    ) {
        System.out.println(multipartFile);
    }

    public void jsonObject(
            JSONArray jsonArray,
            JSONObject jsonObject
    ) {
        System.out.println(jsonObject.toString());
    }

    public void map(
            Map<Map<Long, String>, Map<Long, String>> map
    ) {

    }

    public void generic(ResponseVo<ResponseVo<Map<String, ResponseVo<DemoEntity>>>> responseVo) {

    }

    public void generic(List<Queue<DemoEntity>> list) {

    }

    private Map<String, Object> map = demoService.getMap();

    static {
        map.put("codeBlock", "codeBlock");
        map
    }

    public void testMap() {
//        Map<String, Object> map = new HashMap<>();
        DemoEntity demoEntity = new DemoEntity();
        map.put("1", "value");
        map.put("2", 2);
        map.put("3", demoEntity);

        Map<String, Object> stringObjectMap = (Map<String, Object>) map.get("DemoService.getMap.map.3");
        stringObjectMap.get
        Map<String, Object> stringObjectMap1 = (Map<String, Object>) stringObjectMap.get("DemoService.getMap1.3");
        stringObjectMap1.
        Map<String, Object> map1 = simpleService.getMap();
        Map<String, Object> map11 = demoService.getMap1();
        map.put("list", getListMap1());
        List<Map<String, Object>> list = (List<Map<String, Object>>) map.get("list");
        this.map.getc
    }

    public Map<String, Object> getMap() {
        Map<String, Object> map = new HashMap<>();
        map.put("1", "value");
        map.put("2", 2);
        return map;
    }

    public List<Map<String, Object>> getListMap() {
        return Arrays.asList(
                getMap(),
                getMap()
        );
    }

    public List<Map<String, Object>> getListMap2() {
        return Collections.unmodifiableList(getListMap());
    }


    public List<Map<String, Object>> getListMap1() {
        Map<String, Object> map1 = getMap();
        List<Map<String, Object>> list = new ArrayList<>();
        list.add(0, map1);
        list.addAll(getQueueMap());
        return list;
    }

    public BlockingQueue<Map<String, Object>> getQueueMap() {
        Map<String, Object> map1 = getMap();
        BlockingQueue<Map<String, Object>> queue = new ArrayBlockingQueue<>(10);
        queue.offer(demoService.getMap3());
        return queue;
    }

    public void lambdaMap() {
        List<Map<String, Object>> listMap = getListMap1();
        getListMap1().forEach(map1 -> map1.get);
        listMap.stream()
                .filter(map1 -> map1)
                .map(map1 -> {
                    map1.get
                });
    }

    public void testQueueMap() {
        BlockingQueue<Map<String, Object>> listMap = getQueueMap();
        getListMap1().forEach(map1 -> map1.get);
        listMap.forEach(map1 -> map1.get);
        listMap.stream()
                .filter(map1 -> map1)
                .map(map1 -> {
                    map1.get
                });
    }

    public void forMap() {
        List<Map<String, Object>> listMap = getListMap1();
        for (int i = 0; i < listMap.size(); i++) {
            Map<String, Object> stringObjectMap = listMap.get(i);
            stringObjectMap.get
        }
    }

    public void deepBlock() {
        Map<String, Object> map1 = new HashMap<>();
        map1.put("0", "b");
        for (int i = 0; i < 10; i++) {
            map1.put("a", "b");
            map1.put("c", "b");
            for (int j = 0; j < 10; j++) {
                map1.put("k", "v");
                map1.ge
            }
        }
    }


    public void abstractMethod() {
        Map<String, Object> map = simpleService.getMap();
        List<Map<String, Object>> list = (List<Map<String, Object>>) map.get("SimpleServiceImpl.getMap.3");
        list.forEach(m -> {
            List<Map<String, Object>> list1 = (List<Map<String, Object>>) m.get("SimpleServiceImpl.getMap1.3");
            list1.forEach(m1 -> {
                m1.get
            });
        });
    }

    public void fastJson() {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("fastJson.1", 1);
        jsonObject.fluentPut("fastJson.2", 2);
        JSONObject childJson = new JSONObject();
        childJson.fluentPut("childJson.1", 1);
        childJson.fluentPut("childJson.2", 2);
        jsonObject.fluentPut("childJson", childJson);
        JSONObject childJson_1 = new JSONObject();
        childJson_1.fluentPut("childJson_1.1", 1);
        childJson_1.fluentPut("childJson_1.2", 2);
        childJson.fluentPut("childJson_1",childJson_1);
        jsonObject.put("childArray", jsonArray());
        JSONObject childJson1 = jsonObject.getJSONObject("childJson");
        JSONArray childArray = jsonObject.getJSONArray("childArray");
        JSONObject jsonObject1 = childArray.getJSONObject(0);
        jsonObject.getJSONObject("childJson").getJSONObject("childJson_1").
    }

    public JSONArray jsonArray() {
        JSONArray jsonArray = new JSONArray();
        JSONObject jsonObject = new JSONObject();
        jsonObject.fluentPut("array.child.1", 1);
        jsonObject.fluentPut("array.child.2", 2);
        jsonArray.add(jsonObject);
        JSONObject jsonObject1 = jsonArray.getJSONObject(0);
        jsonObject1.getch
        return jsonArray;
    }

    public void jsonParseObject() {
        JSONObject jsonObject = JSON.parseObject("{\n" +
                "    \"call_back_url\": \"https://tx-inner-biz-sit.remacsmart.com/tx/platform-biz/remac-tx-after-sale/skuservicerel/sync/doServiceProductSync\",\n" +
                "    \"data\":\n" +
                "    {\n" +
                "        \"data1\":\n" +
                "        {\n" +
                "            \"data2\":\n" +
                "            {\n" +
                "                \"data3\":\n" +
                "                {\n" +
                "                    \"id3\": \"1\"\n" +
                "                },\n" +
                "                \"id2\": \"1\"\n" +
                "            },\n" +
                "            \"id1\": \"1\"\n" +
                "        },\n" +
                "        \"dbName\": \"tg_sit_admin\",\n" +
                "        \"id\": \"2091\",\n" +
                "        \"operateType\": \"UPDATE\",\n" +
                "        \"tableName\": \"tg_service\",\n" +
                "        \"timestamp\": \"1710741323000\"\n" +
                "    },\n" +
                "    \"mac\": \"d33daba7f5db4df05bd20a468f7a27a3e66c4f4a434075460b009e0e385bba1d\",\n" +
                "    \"noncestr\": \"4bbfbf020129de9877c963789734a5eb\",\n" +
                "    \"timestamp\": 1710741324371,\n" +
                "    \"type\": \"service\"\n" +
                "}");
        JSONObject jsonObject1 = jsonObject.getJSONObject("data")
                .getJSONObject("data1");
        JSONObject jsonObject2 = jsonObject1.getJSONObject("data2").getJSONObject("data3");
        jsonObject2
    }

    public void jsonParseObject1() {
        JSONObject jsonObject = JSON.parseObject("{\n" +
                "    \"call_back_url\": \"https://tx-inner-biz-sit.remacsmart.com/tx/platform-biz/remac-tx-after-sale/skuservicerel/sync/doServiceProductSync\",\n" +
                "    \"data\": \"{\\\"dbName\\\":\\\"tg_sit_admin\\\",\\\"id\\\":\\\"2091\\\",\\\"operateType\\\":\\\"UPDATE\\\",\\\"tableName\\\":\\\"tg_service\\\",\\\"timestamp\\\":\\\"1710741323000\\\"}\",\n" +
                "    \"mac\": \"d33daba7f5db4df05bd20a468f7a27a3e66c4f4a434075460b009e0e385bba1d\",\n" +
                "    \"noncestr\": \"4bbfbf020129de9877c963789734a5eb\",\n" +
                "    \"timestamp\": 1710741324371,\n" +
                "    \"type\": \"service\"\n" +
                "}");
//        jsonObject.put("key","value");
        JSONObject data = jsonObject.getJSONObject("data");


    }

    public void jsonParseArray(){
        JSONArray jsonArray = JSON.parseArray("[{" +
                "\"id\":\"1\"}]");
        JSONObject jsonObject = jsonArray.getJSONObject(0);
        jsonObject.getString("id")
    }

}
